package com.dandelion.manager.system.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dandelion.commons.annotation.SystemLog;
import com.dandelion.commons.constants.BaseConst;
import com.dandelion.commons.web.controller.BaseController;
import com.dandelion.commons.web.model.AjaxResponse;
import com.dandelion.commons.web.model.DataGrid;
import com.dandelion.manager.system.domain.Permit;
import com.dandelion.manager.system.service.PermitService;

@Controller
@RequestMapping("/manager/system/permit")
public class PermitController extends BaseController {

	@Autowired
	public PermitService service ;
	
	/**
	 * 主页
	 * @return
	 */
	@RequestMapping(value="/main", method=RequestMethod.GET)
	public String main(Model model) {
		return viewName("main") ;
	}
	
	/**
	 * 表单页面
	 * @param id
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/form", method=RequestMethod.GET)
	public String form(Long id, Model model) {
		if(null != id) {
			model.addAttribute("id", id) ;
		}
		return viewName("form") ;
	}
	
	/**
	 * 添加
	 * @param dto
	 * @return
	 */
	@SystemLog(module=BaseConst.MODULE_SYSTEM+"[权限管理]", method="添加权限")
	@RequestMapping(value="/add", method=RequestMethod.POST)
	public @ResponseBody AjaxResponse add(Permit dto) {
		return this.service.add(dto);
	}
	
	/**
	 * 删除
	 * @param ids 数组
	 * @return
	 */
	@SystemLog(module=BaseConst.MODULE_SYSTEM+"[权限管理]", method="删除权限")
	@RequestMapping(value="/delete", method=RequestMethod.POST)
	public @ResponseBody AjaxResponse delete(Long[] ids) {
		return this.service.deleteBatch(ids);
	}
	
	/**
	 * 修改
	 * @param dto
	 * @return
	 */
	@SystemLog(module=BaseConst.MODULE_SYSTEM+"[权限管理]", method="修改权限")
	@RequestMapping(value="/update", method=RequestMethod.POST)
	public @ResponseBody AjaxResponse update(Permit dto) {
		return this.service.update(dto);
	}
	
	/**
	 * 根据ID获取数据
	 * @param id
	 * @return
	 */
	@SystemLog(module=BaseConst.MODULE_SYSTEM+"[权限管理]", method="加载权限")
	@RequestMapping(value="/get/{id}", method=RequestMethod.GET)
	public @ResponseBody Permit get(@PathVariable Long id) {
		return this.service.get(id) ;
	}
	
	/**
	 * 数据列表-分页查询
	 * @param dto
	 * @return
	 */
	@SystemLog(module=BaseConst.MODULE_SYSTEM+"[权限管理]", method="加载权限列表")
	@RequestMapping(value="/datagrid")
	public @ResponseBody DataGrid<Permit> datagrid(Permit dto) {
		return this.service.datagrid(dto) ;
	}
	
	/**
	 * 查询所有
	 * @param dto
	 * @return
	 */
	@SystemLog(module=BaseConst.MODULE_SYSTEM+"[权限管理]", method="加载所有权限")
	@RequestMapping(value="/getAllList")
	public @ResponseBody List<Permit> getAllList(Permit dto) {
		return this.service.getAllList(dto) ;
	}
	
}
